require(['topBar', 'layout', 'date', 'grid'], function () {
    //提交到后台参数
    var postData,
        $dialog,//查看弹出窗口
        $grid = $('#grid');//数据展示grid
    $('#top').topBar({
        left: [{
            type: 'filter-more',
            dateType:'custom',
            search: function () {
                if (getPostData()) {
                    $grid.grid('setGridParam', {
                        page: 1,
                        datatype: "json",
                        postData: postData
                    }).trigger("reloadGrid");
                }
            },
            item: [
                {
                    text: '时间快捷',
                    name1: 'beginTime',
                    name2: 'endTime',
                    type: 'dateLine'
                },
                {
                    text: '停留时间超过',
                    name: 'duration',
                    type: 'item-select',
                    data: [
                        {text: '10分钟以上', value: '10'},
                        {text: '20分钟以上', value: '20'},
                        {text: '30分钟以上', value: '30'}
                    ]
                }
            ]
        }]
    });

    $('body').layout();

    $grid.grid({
        multiselect: false,
        url: "/electFencAlm/searchElectFencExDetail.htm",
        colModel: [
            {name: "fencId", label: "fencId", hidden: true},
            {name: "fencCd", label: "fencCd", hidden: true},
            {name: "inLgt", label: "inLgt", hidden: true},
            {name: "inLtt", label: "inLtt", hidden: true},
            {name: "inDrc", label: "inDrc", hidden: true},
            {name: "outLgt", label: "outLgt", hidden: true},
            {name: "outLtt", label: "outLtt", hidden: true},
            {name: "outDrc", label: "outDrc", hidden: true},
            {name: "licPltNo", label: "车牌号"},
            {name: "carInCd", label: "车辆编号"},
            {name: "lineName", label: "运营线路"},
            {name: "organName", label: "所属机构"},
            {name: "fencName", label: "区域名称"},
            {name: "inTime", label: "驶入时间"},
            {name: "outTime", label: "驶出时间"},
            {name: "durationTime", label: "停留时长"},
            {
                name: "operate", width: 80, label: '操作', align: "center",
                formatter: 'operArea',
                formatoptions: [{
                    text: '查看',
                    css: 'operate-scan',
                    click: function (data) {
                        viewElectFencAlm();
                        getElectFencAlmInfo(data.fencId);
                        showCarInfo(data);
                    }
                }]
            }
        ]
    });

    //获取左侧选择的节点信息
    function getPostData() {
        var rcx = commonFun.getTreeCheckNodeToArgs();
        if (rcx) {
            postData = $.extend(rcx, $("#top").parent().getValues());
        }
        return rcx;
    }

    function getElectFencAlmInfo(fencId) {
        $.ajaxExt({
            url: "/electFencSet/getBaseElectFencById.htm",
            data: {"fencId": fencId}
        }).done(function (data) {
            $dialog.dialog('exec', 'showSingleElectFencMap', data);
        });
    }

    function showCarInfo(data){										// 在这里构造车辆数据的数组
        // 在这里构造车辆数据的数组
        var ary = [];
        var objIn = new Object();  										//车辆数据
        objIn.licPltNo = data.licPltNo;	 										//车牌号
        objIn.driverName = ""; 									//驾驶员
        objIn.loLgt = data.inLgt; 											//经度
        objIn.loLtt = data.inLtt; 											//纬度
        objIn.direction = data.inDrc; 										//异常类型 字符串表示
        objIn.inoutTime = data.inTime;                     //发生车速
        ary.push(objIn);
        var objOut = new Object();  										//车辆数据
        objOut.licPltNo = data.licPltNo;	 										//车牌号
        objOut.driverName = ""; 									//驾驶员
        objOut.loLgt = data.outLgt; 											//经度
        objOut.loLtt = data.outLtt; 											//纬度
        objOut.direction = data.outDrc; 										//异常类型 字符串表示
        objOut.inoutTime = data.outTime;                     //发生车速
        ary.push(objOut);
        $dialog.dialog('exec', 'showMapLocationForArray', ary);
    }

    //在地图上查看对应的电子围栏
    function viewElectFencAlm() {
        if (!$dialog) {
            $dialog = $('<div>').dialog({
                title: '查看电子围栏',
                url: './service/report/ElectFencMap.htm',
                height: $(window.parent).height() * 0.8,
                width: $(window.parent).width() * 0.8,
                close: function () {
                    $(this).dialog('exec', 'clear');
                }
            });
        }
        $dialog.dialog('open');
    }
});